﻿using System.Collections.Generic;
using System.Linq;
using Ds.DataBase.Model;

namespace Ds.DataBase.Migrations.SeedData
{
    public class PowerTreeCreator
    {
        public static List<PowerTree> PowerTrees { get; private set; }

        private readonly UserInfoClassContext _context;

        static PowerTreeCreator()
        {

            PowerTrees = new List<PowerTree>
            {
                new PowerTree(){mc = "个人管理",ZhiWeis = new List<ZhiWei>(),ptpath = "/",uri = "javascript:void(0)"},
                new PowerTree(){mc = "员工操作",ZhiWeis = new List<ZhiWei>(),ptpath = "/",uri = "javascript:void(0)"},
                new PowerTree(){mc = "综合信息",ZhiWeis = new List<ZhiWei>(),ptpath = "/",uri = "javascript:void(0)"},
                new PowerTree(){mc = "系统管理",ZhiWeis = new List<ZhiWei>(),ptpath = "/",uri = "javascript:void(0)"},
                new PowerTree(){mc = "评审操作",ZhiWeis = new List<ZhiWei>(),ptpath = "/",uri = "javascript:void(0)"}

            };
            foreach (var powerTree in PowerTrees)
            {
                if (powerTree.mc == "个人管理")
                {
                    powerTree.SonPowerTrees = new List<PowerTree>
                 {
                     new PowerTree(){mc = "个人资料",ZhiWeis = new List<ZhiWei>(),ptpath = "/"+powerTree.ptid+"/",uri = "javascript:void(0)"},
                     new PowerTree(){mc = "修改密码",ZhiWeis = new List<ZhiWei>(),ptpath = "/"+powerTree.ptid+"/",uri = "javascript:void(0)"}
                 };
                }
                if (powerTree.mc == "员工操作")
                {
                    powerTree.SonPowerTrees = new List<PowerTree>
                    {
                        new PowerTree(){mc = "个人工作计划上报",ZhiWeis = new List<ZhiWei>(),ptpath = "/"+powerTree.ptid+"/",uri = "javascript:void(0)"},
                        new PowerTree(){mc = "历史工作计划",ZhiWeis = new List<ZhiWei>(),ptpath = "/"+powerTree.ptid+"/",uri = "javascript:void(0)"},
                        new PowerTree(){mc = "历史绩效考核",ZhiWeis = new List<ZhiWei>(),ptpath = "/"+powerTree.ptid+"/",uri = "javascript:void(0)"}
                    };
                }
                if (powerTree.mc == "综合信息")
                {
                    powerTree.SonPowerTrees = new List<PowerTree>
                    {
                        new PowerTree(){mc = "全校考核结果",ZhiWeis = new List<ZhiWei>(),ptpath = "/"+powerTree.ptid+"/",uri = "javascript:void(0)"},
                        new PowerTree(){mc = "历史考核结果",ZhiWeis = new List<ZhiWei>(),ptpath = "/"+powerTree.ptid+"/",uri = "javascript:void(0)"}
                    };
                }
                if (powerTree.mc == "系统管理")
                {
                    powerTree.SonPowerTrees = new List<PowerTree>
                    {
                        new PowerTree(){mc = "教职工管理",ZhiWeis = new List<ZhiWei>(),ptpath = "/"+powerTree.ptid+"/",uri = "javascript:void(0)"},
                        new PowerTree(){mc = "职务管理",ZhiWeis = new List<ZhiWei>(),ptpath = "/"+powerTree.ptid+"/",uri = "javascript:void(0)"},
                        new PowerTree(){mc = "科室管理",ZhiWeis = new List<ZhiWei>(),ptpath = "/"+powerTree.ptid+"/",uri = "javascript:void(0)"},
                        new PowerTree(){mc = "考核表管理",ZhiWeis = new List<ZhiWei>(),ptpath = "/"+powerTree.ptid+"/",uri = "javascript:void(0)"},
                        new PowerTree(){mc = "微调范围",ZhiWeis = new List<ZhiWei>(),ptpath = "/"+powerTree.ptid+"/",uri = "javascript:void(0)"},
                        new PowerTree(){mc = "考核范围",ZhiWeis = new List<ZhiWei>(),ptpath = "/"+powerTree.ptid+"/",uri = "javascript:void(0)"},
                        new PowerTree(){mc = "工作计划评审范围",ZhiWeis = new List<ZhiWei>(),ptpath = "/"+powerTree.ptid+"/",uri = "javascript:void(0)"},
                        new PowerTree(){mc = "定档",ZhiWeis = new List<ZhiWei>(),ptpath = "/"+powerTree.ptid+"/",uri = "javascript:void(0)"},
                        new PowerTree(){mc = "审核新注册教职工",ZhiWeis = new List<ZhiWei>(),ptpath = "/"+powerTree.ptid+"/",uri = "javascript:void(0)"}
                    };
                }
                if (powerTree.mc == "评审操作")
                {
                    powerTree.SonPowerTrees = new List<PowerTree>
                    {
                        new PowerTree(){mc = "被考核人员",ZhiWeis = new List<ZhiWei>(),ptpath = "/"+powerTree.ptid+"/",uri = "javascript:void(0)"},
                        new PowerTree(){mc = "评审工作计划",ZhiWeis = new List<ZhiWei>(),ptpath = "/"+powerTree.ptid+"/",uri = "javascript:void(0)"},
                        new PowerTree(){mc = "考核范围内微调",ZhiWeis = new List<ZhiWei>(),ptpath = "/"+powerTree.ptid+"/",uri = "javascript:void(0)"},
                        new PowerTree(){mc = "确认考核结果",ZhiWeis = new List<ZhiWei>(),ptpath = "/"+powerTree.ptid+"/",uri = "javascript:void(0)"}
                    };
                }
            }
        }

        public PowerTreeCreator(UserInfoClassContext context)
        {
            _context = context;
        }

        public void Create()
        {
            CreatePowerTrees();
        }

        private void CreatePowerTrees()
        {
            foreach (var language in PowerTrees)
            {
                AddLanguageIfNotExists(language);
            }
        }

        private void AddLanguageIfNotExists(PowerTree powerTree)
        {
            if (_context.PowerTreesContext.Any(l => l.mc == powerTree.mc))
            {
                return;
            }
            _context.PowerTreesContext.Add(powerTree);
            _context.SaveChanges();
        }
    }
}
